import React from 'react';
import ReactDOM from 'react-dom';
import { Link } from 'react-router';
import { Breadcrumb, Button, Form, Input, Table, Row, Col,Select  } from 'antd';

const Demo = React.createClass({

  contextTypes: {
    router: React.PropTypes.object
  },

  getInitialState() {
    return {
      item: '出租管理'
    }
  },

  handleRouter() {
    let path = this.props.location.pathname;
    let state = this.props.location.state;
    let lastPath = path.split('/')[path.split('/').length - 1];
    let index = '/landlord/rentManage/signUpOrder/list';
    let add = '/landlord/rentManage/signUpOrder/add';
    let goPathUrl = ( lastPath == 'list' || lastPath == 'signUpOrder') ? add : index;
    this.context.router.push({pathname: goPathUrl, state: {...state}});
  },

  render() {
    let path = this.props.location.pathname;
    let lastPath = path.split('/')[path.split('/').length - 1];
    let routerItem = {
      'list': '签约单列表',
      'signUpOrder': '签约单列表',
      'add': '新增签约单',
      'update': '修改签约单',
      'details': '签约单详情',
    };
    console.log(lastPath)
    let txtName = ( lastPath == 'list' || lastPath == 'signUpOrder') ? '签约' : '返回';

    return (
      <div>
        <div className="nav-bar">
          <Breadcrumb separator="-">
            <Breadcrumb.Item>出租管理</Breadcrumb.Item>
            <Breadcrumb.Item>{routerItem[lastPath]}</Breadcrumb.Item>
          </Breadcrumb>
          {(lastPath !== 'list' && lastPath !== 'signUpOrder' )? <Button className="ant-button" type="primary" onClick={this.handleRouter}>{txtName}</Button> : null}
        </div>
        <div className="content-wrapper">
          {this.props.children}
        </div>

      </div>

    );
  }
});

export default Demo